package samsung.sds.systemMonitor.exceptionMonitor.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import samsung.sds.system.common.baseQuery.model.PageData;
import samsung.sds.system.common.model.QueryParam;
import samsung.sds.system.utils.CommonTools;
import samsung.sds.systemMonitor.exceptionMonitor.model.ExceptionEntity;
import samsung.sds.systemMonitor.exceptionMonitor.service.ExceptionMonitorService;

/**
 *  @author deng1.pan
 *  @createDate 2016-02-03
 *  
 *  异常日志模块的控制器
 */
@Controller
@RequestMapping("/systemMonitor/exceptionMonitor")
public class ExceptionMonitorController {
	@Autowired
	private ExceptionMonitorService exceptionMonitorServiceImpl;
	
	/**
	 * 跳转到异常列表的主界面
	 * @return
	 */
	@RequestMapping(value = "/exceptionList", method = RequestMethod.POST)
	public String exceptionList(HttpServletRequest request, ModelMap modelMap) {
		String pageType = request.getParameter("pageType");
		modelMap.addAttribute("pageType", pageType);
		modelMap.addAttribute("currentTime", CommonTools.getCurrentDateTime());
		return "/systemMonitor/exceptionMonitor/exceptionMonitorList";
	}
	
	/**
	 * 实现异常列表的分页查询
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/listPageData", method = RequestMethod.POST)
	@ResponseBody
	public PageData<ExceptionEntity> listPageData(HttpServletRequest request) {
		QueryParam param = CommonTools.getQueryParam(request);
		return exceptionMonitorServiceImpl.queryListPage(param);
	}
	
	/**
	 * 获取默认查询参数
	 * @return
	 */
	@RequestMapping(value = "/getQueryParam", method = RequestMethod.POST)
	@ResponseBody
	public List<String> getQueryParam(){
		return exceptionMonitorServiceImpl.getQueryParam();
	}
	
	/**
	 * 查看被选中异常的详情
	 * @param modelMap
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/viewDetails", method = RequestMethod.POST)
	public String viewDetails(ModelMap modelMap,String exceptionId){
		modelMap.put("exceptionEntity", exceptionMonitorServiceImpl.findEntityById(exceptionId));
		return "/systemMonitor/exceptionMonitor/exceptionMonitorDetail";
	}
}
